package implementor;


import daoInterface.CategoryDao;
import dbhandeling.Crude;
import dto.Category;

public class CategoryImp extends Crude implements CategoryDao
{

	String className = new Category().getClass().getName();
	
	@Override
	public void add(Category cat) throws Exception {
		super.insert(cat);
		
	}

	@Override
	public void update(Category cat) throws Exception {
		super.update(className, "leafLevel", cat.getLeafLevel()+"", "catCode", cat.getCatCode());
		super.update(className, "leafId", cat.getLeafId(), "catCode", cat.getCatCode());
		super.update(className, "leafName", cat.getLeafName(), "catCode", cat.getCatCode());
		super.update(className, "parentLeafId", cat.getParentLeafId(), "catCode", cat.getCatCode());
	}

	@Override
	public void delete(Category cat) {
		super.delete(className, "catCode", cat.getCatCode());
		
	}

	@Override
	public Category[] retrieveArray(String conditionField,
			String conditionValue) throws Exception {
		Object[] cat= super.retreiveArrayOnCondition(className, conditionField, conditionValue);
		Category[]s=new Category[cat.length];
		
		for(int i=0;i<s.length;i++)
			s[i]=(Category) cat[i];
		return s;
	}

	@Override
	public Category[] retrieveAll() throws Exception {
		Object[] cat= super.retreiveAll(className);
		Category[]s=new Category[cat.length];
		
		for(int i=0;i<s.length;i++)
			s[i]=(Category) cat[i];
		return s;
	}

	@Override
	public Category retrieve( String conditionField,
			String conditionValue) throws Exception {
		Category cat=(Category) super.retreive(className, conditionField, conditionValue);
		return cat;
	}	
	public int getAutoGenratedKey()
	{
		 int key=super.getAutoGenratedKey(className,"autoId") ;
		 return key;
	}

}
